import { ElMessageBox, ElMessage } from 'element-plus'
import { AllStateType } from '@/store/storeType'
import { Store } from 'vuex'

export const messageBoxFunc = (dispatchName: string, store: Store<AllStateType>, dispatchData: any = {}, callback?: () => void) => {
  ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
      store.dispatch(dispatchName, dispatchData).then((res: any) => {
        if (res?.data?.meta?.status === 200) {
          ElMessage({
            type: 'success',
            message: res.data.meta.msg,
          })
          if (callback) {
            callback()
          }
        }
      })
    }).catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消删除',
      });
    });
}